<%--
  Created by IntelliJ IDEA.
  User: csnf
  Date: 2024/12/23
  Time: 15:04
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%--导入标签库jstl--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>学生列表</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
        }
        .container {
            width: 90%;
            max-width: 1200px;
            margin: 50px auto;
            background: white;
            padding: 20px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            border-radius: 8px;
            animation: fadeIn 0.5s ease-in-out;
        }
        @keyframes fadeIn {
            from { opacity: 0; }
            to { opacity: 1; }
        }
        h1 {
            text-align: center;
            color: #333;
            margin-bottom: 20px;
        }
        form {
            display: flex;
            justify-content: space-between;
            margin-bottom: 20px;
        }
        input[type="text"] {
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 4px;
            transition: border-color 0.3s ease;
        }
        input[type="text"]:focus {
            border-color: #007bff;
        }
        input[type="submit"], a.button {
            padding: 10px 20px;
            background-color: #28a745;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            transition: background-color 0.3s ease;
            text-decoration: none;
        }
        input[type="submit"]:hover, a.button:hover {
            background-color: #218838;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }
        th, td {
            padding: 12px;
            text-align: left;
            border-bottom: 1px solid #ddd;
        }
        th {
            background-color: #f2f2f2;
            color: #333;
        }
        tr:nth-child(even) {
            background-color: #f9f9f9;
        }
        tr:hover {
            background-color: #f1f1f1;
        }
        a.action-link {
            color: #007bff;
            text-decoration: none;
            margin-right: 10px;
            transition: color 0.3s ease;
        }
        a.action-link:hover {
            text-decoration: underline;
            color: #0056b3;
        }
        /* 确保小屏幕下表格内容可滚动 */
        @media (max-width: 768px) {
            .container {
                overflow-x: auto;
            }
            table {
                width: 100%;
                display: block;
            }
        }
    </style>
</head>
<body>
<div class="container">
    <h1>学生列表</h1>
    <form action="Studentservlet" method="get">
        <input type="text" name="sName" placeholder="请输入姓名">
        <input type="submit" value="查询">
        <a href="getAllClazz" class="button">添加</a>
    </form>

    <table>
        <tr>
            <th>编号</th>
            <th>姓名</th>
            <th>生日</th>
            <th>性别</th>
            <th>班级</th>
            <th>操作</th>
        </tr>
        <c:forEach items="${stuList}" var="stu">
            <tr>
                <td>${stu.sId}</td>
                <td>${stu.sName}</td>
                <td>${stu.birth}</td>
                <td>${stu.gender}</td>
                <td>${stu.clazz.cName}</td>
                <td>
                    <a href="getStudentById?sId=${stu.sId}" class="action-link">修改</a>
                    <a href="javascript:void(0)" onclick="confirmDelete(${stu.sId})" class="action-link">删除</a>
                </td>
            </tr>
        </c:forEach>
    </table>
</div>

<script>
    function confirmDelete(id) {
        if (confirm("确定删除吗？")) {
            location.href = "deleteById?sId=" + id;
        }
    }
</script>
</body>
</html>
